<template>
	<view class="pics">
		<!-- 左侧 -->
		<scroll-view scroll-y="true"  class="left">
			<view :class="active === index?'active': '' " 
			v-for="(item,index) in cates" :key="index"
			@click="clickActive(index,item.id)">{{item.title}}</view>
		</scroll-view>
		
		<!-- 右侧 -->
		<scroll-view scroll-y="true"  class="right">
			<view class="item" v-for="(item, index) in imgs" :key="index">
				<image src="../../static/4a91ad8e67b2c92de2418e5913767a47.jpg" mode="aspectFill"
				@click="previewImg"></image>
				<text>{{item.title}}</text>
			</view>
			<view class="noData" v-if="imgs.length === 0">
				暂无数据
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				/* 分类列表 */
				cates: [],
				// 激活标志
				active:0,
				// 图片数据
				imgs: []
			}
		},
		onLoad() {
			this.getPicesCate()
		},
		methods: {
			// 获取图片分类列表
			async getPicesCate() {
				const res = await this.$myRequest({
					url: '/getimgcategory'
				})
				this.cates = res.data.message
				this.clickActive(0, this.cates[0].id)
			},
			// 分类点击事件, 获取分类下图片
			async clickActive(index, id){
				console.log(index)
				this.active = index
				
				// 发起请求
				const res = await this.$myRequest({
					url:`/getimages/${id}`,
				})
				this.imgs = res.data.message
			},
			// 放大预览图片
			previewImg(){
				uni.previewImage({
					urls: 'https://gitee.com/zy7y/blog_images/blob/master/img/20210113233941.png'
				})
				console.log("预览图片")
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.pics{
		height: 100%;
		display: flex;
		padding-top: 10rpx;
		.left{
			width: 200rpx;
			height: 100%;
			view{
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top:1px solid #eee ;
			}
			.active{
				background-color: $shop-color;
				color: #FFFFFF;
			}
		}
		.right{
			width: 550rpx;
			margin: 10rpx auto;
			.item{
				image{
					height: 530rpx;
					width: 530rpx;
					border-radius: 5px;
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
				padding-bottom: 10rpx;
			}
		}
		.noData{
			text-align: center;
			// margin: 0 auto;
			line-height: 750rpx;
			color: #999999;
			font-size: 60rpx;
			
		}
	}

</style>
